home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_DetermineSize.c < prev    next >
C/C++ Source or Header  |  1996-10-08  |  23KB  |  968 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. LONG
  15. LTP_GetPickerSize(LayoutHandle *Handle)
  16. {
  17.     LONG margin,width;
  18.  
  19.     width = (Handle->TextAttr->ta_YSize * Handle->AspectY) / Handle->AspectX;
  20.  
  21.     if(width < 8)
  22.         width = 8;
  23.  
  24.     margin = 2 + (width + 15) / 16;
  25.  
  26.     return((LONG)(margin + (((115 * width) / 150) & ~1) + 1 + margin));
  27. }
  28.  
  29. VOID
  30. LTP_DetermineSize(LayoutHandle *Handle,ObjectNode *Node)
  31. {
  32.     if(!Handle->Failed)
  33.     {
  34.         LONG i,Len,Width,Max,Plus;
  35.  
  36.         if(Node->Label)
  37.         {
  38.             LONG LabelWidth = LT_LabelWidth(Handle,Node->Label);
  39.  
  40.             if(Node->LabelChars * Handle->GlyphWidth > LabelWidth)
  41.                 LabelWidth = Node->LabelChars * Handle->GlyphWidth;
  42.  
  43.             Node->LabelWidth = LabelWidth;
  44.         }
  45.         else
  46.             Node->LabelWidth = 0;
  47.  
  48.         switch(Node->Type)
  49.         {
  50. #ifdef DO_BOOPSI_KIND
  51.             case BOOPSI_KIND:
  52.  
  53.                 if(Node->Special.BOOPSI.ExactWidth)
  54.                     Node->Width = Node->Special.BOOPSI.ExactWidth;
  55.                 else
  56.                     Node->Width = Node->Chars * Handle->GlyphWidth;
  57.  
  58.                 if(Node->Special.BOOPSI.ExactHeight)
  59.                     Node->Height = Node->Special.BOOPSI.ExactHeight;
  60.                 else
  61.                     Node->Height = Node->Lines * Handle->GlyphHeight;
  62.  
  63.                 if(Node->Special.BOOPSI.RelFontHeight)
  64.                     Node->Height = Handle->GlyphHeight + Node->Special.BOOPSI.RelFontHeight;
  65.  
  66.                 break;
  67. #endif    /* DO_BOOPSI_KIND */
  68.  
  69. #ifdef DO_LEVEL_KIND
  70.             case LEVEL_KIND:
  71.  
  72.                 Node->Width        = 6 + Node->Chars * Handle->GlyphWidth + 6;
  73.                 Node->Height    = 2 + Handle->GlyphHeight + 1;
  74.  
  75.                 LTP_GetStorage(Node);
  76.  
  77.                 if(Node->Current > Node->Max)
  78.                 {
  79.                     Node->Current = Node->Max;
  80.  
  81.                     LTP_PutStorage(Node);
  82.                 }
  83.  
  84.                 if(Node->Current < Node->Min)
  85.                 {
  86.                     Node->Current = Node->Min;
  87.  
  88.                     LTP_PutStorage(Node);
  89.                 }
  90.  
  91.                 if(!Node->Special.Level.MaxLevelWidth || Handle->Rescaled)
  92.                 {
  93.                     LTP_LevelWidth(Handle,Node->Special.Level.LevelFormat,Node->Special.Level.DispFunc,Node->Min,Node->Max,&Node->Special.Level.MaxLevelWidth,NULL,Node->Special.Level.FullLevelCheck);
  94.  
  95.                     Node->Special.Level.MaxLevelWidth += TextLength(&Handle->RPort," ",1);
  96.                 }
  97.  
  98.                 Node->Special.Level.Handle                = Handle;
  99.                 Node->Special.Level.CustomHook.h_Entry    = (HOOKFUNC)LTP_LevelGadgetDispatcher;
  100.  
  101.                 if(!Node->Special.Level.Plus)
  102.                     Node->Special.Level.Plus = Node->Min;
  103.  
  104.                 if(Node->LabelChars * Handle->GlyphWidth > Node->LabelWidth)
  105.                     Node->LabelWidth = Node->LabelChars * Handle->GlyphWidth;
  106.  
  107.                 if(Node->Special.Level.LevelPlace == PLACETEXT_LEFT && Node->LabelPlace == PLACE_LEFT)
  108.                     Node->LabelWidth += Node->Special.Level.MaxLevelWidth;
  109.  
  110.                 break;
  111. #endif    /* DO_LEVEL_KIND */
  112.             case GROUP_KIND:
  113.  
  114.                 LTP_LayoutGroup(Handle,Node);
  115.  
  116.                 break;
  117.  
  118.             case XBAR_KIND:
  119.  
  120.                 Node->Width        = Handle->GlyphWidth;
  121.                 Node->Height    = 6;
  122.  
  123.                 break;
  124.  
  125.             case YBAR_KIND:
  126.  
  127.                 Node->Width        = 6;
  128.                 Node->Height    = Handle->GlyphHeight;
  129.  
  130.                 break;
  131.  
  132.             case FRAME_KIND:
  133.  
  134.                 if(Node->Special.Frame.DrawBox)
  135.                 {
  136.                     Node->Width        = 4 + Node->Special.Frame.InnerWidth + 4;
  137.                     Node->Height    = 2 + Node->Special.Frame.InnerHeight + 2;
  138.                 }
  139.                 else
  140.                 {
  141.                     Node->Width        = Node->Special.Frame.InnerWidth;
  142.                     Node->Height    = Node->Special.Frame.InnerHeight;
  143.                 }
  144.  
  145.                 break;
  146.  
  147.             case BOX_KIND:
  148.  
  149.                 Node->LabelWidth = 0;
  150.  
  151.                 if(Node->Special.Box.Labels)
  152.                 {
  153.                     for(i = 0 ; i < Node->Lines ; i++)
  154.                     {
  155.                         if((Width = TextLength(&Handle->RPort,Node->Special.Box.Labels[i],strlen(Node->Special.Box.Labels[i]))) > Node->LabelWidth)
  156.                             Node->LabelWidth = Width;
  157.                     }
  158.                 }
  159.  
  160.                 if(Node->LabelChars)
  161.                 {
  162.                     if(Node->LabelChars * Handle->GlyphWidth > Node->LabelWidth)
  163.                         Node->LabelWidth = Node->LabelChars * Handle->GlyphWidth;
  164.                     else
  165.                         Node->LabelWidth = ((Node->LabelWidth + Node->LabelChars - 1) / Node->LabelChars) * Node->LabelChars;
  166.                 }
  167.  
  168.                 Max = Node->Chars;
  169.  
  170.                 if(Node->Special.Box.Lines)
  171.                 {
  172.                     LONG MaxWidth = 0;
  173.  
  174.                     for(i = 0 ; i < Node->Lines ; i++)
  175.                     {
  176.                         if(Node->Special.Box.Lines[i])
  177.                         {
  178.                             if(Len = strlen(Node->Special.Box.Lines[i]))
  179.                             {
  180.                                 if((Width = TextLength(&Handle->RPort,Node->Special.Box.Lines[i],Len)) > MaxWidth)
  181.                                     MaxWidth = Width;
  182.                             }
  183.                         }
  184.                     }
  185.  
  186.                     if(Max < (MaxWidth + Handle->GlyphWidth - 1) / Handle->GlyphWidth)
  187.                         Max = (MaxWidth + Handle->GlyphWidth - 1) / Handle->GlyphWidth;
  188.                 }
  189.  
  190.                 Node->Height    = 2 + Node->Lines * Handle->GlyphHeight + 2;
  191.                 Node->Width        = 4 + Max * Handle->GlyphWidth + 4;
  192.  
  193.                 break;
  194.  
  195.             case BLANK_KIND:
  196.  
  197.                 Node->Width            = Handle->GlyphWidth;
  198.                 Node->Height        = Handle->GlyphHeight;
  199.                 Node->Label            = "";
  200.                 Node->LabelWidth    = 0;
  201.                 Node->LabelPlace    = PLACE_IN;
  202.  
  203.                 break;
  204.  
  205.             case BUTTON_KIND:
  206.  
  207.                 if(!Node->Special.Button.Lines && Node->Label)
  208.                 {
  209.                     LONG i,Len = strlen(Node->Label),Count = 0;
  210.  
  211.                     for(i = 0 ; i < Len ; i++)
  212.                     {
  213.                         if(Node->Label[i] == '\n')
  214.                             Count++;
  215.                     }
  216.  
  217.                     if(Count)
  218.                     {
  219.                         STRPTR *Lines;
  220.  
  221.                         if(Lines = (STRPTR *)LTP_Alloc(Handle,(Count + 2) * sizeof(STRPTR) + Len + 1))
  222.                         {
  223.                             STRPTR String = (STRPTR)(&Lines[Count + 2]);
  224.  
  225.                             strcpy(String,Node->Label);
  226.  
  227.                             Node->Special.Button.Lines = Lines;
  228.  
  229.                             if(Node->Special.Button.KeyStroke)
  230.                                 Node->Special.Button.KeyStroke = &String[((ULONG)Node->Special.Button.KeyStroke) - ((ULONG)Node->Label)];
  231.  
  232.                             do
  233.                             {
  234.                                 *Lines++ = String;
  235.  
  236.                                 for(i = 0 ; String[i] ; i++)
  237.                                 {
  238.                                     if(String[i] == '\n')
  239.                                     {
  240.                                         String[i] = 0;
  241.  
  242.                                         String = &String[i + 1];
  243.  
  244.                                         break;
  245.                                     }
  246.                                 }
  247.                             }
  248.                             while(Count--);
  249.                         }
  250.                         else
  251.                             break;
  252.                     }
  253.                 }
  254.  
  255.                 if(Node->Special.Button.Lines)
  256.                 {
  257.                     STRPTR    *Index = Node->Special.Button.Lines;
  258.                     LONG     Count = 0,Width,MaxWidth = 0,Height;
  259.  
  260.                     while(*Index)
  261.                     {
  262.                         Count++;
  263.  
  264.                         if((Width = LT_LabelWidth(Handle,*Index)) > MaxWidth)
  265.                             MaxWidth = Width;
  266.  
  267.                         Index++;
  268.                     }
  269.  
  270.                     Node->Special.Button.LineCount = Count;
  271.  
  272.                     if(Node->Chars * Handle->GlyphWidth > MaxWidth)
  273.                         MaxWidth = Node->Chars * Handle->GlyphWidth;
  274.  
  275.                     if(Node->Lines > Count)
  276.                         Count = Node->Lines;
  277.  
  278.                     Height = Count * Handle->GlyphHeight;
  279.  
  280.                     if(Node->Special.Button.ExtraFat)
  281.                     {
  282.                         Node->Width        = 6 + Handle->GlyphWidth + MaxWidth + Handle->GlyphWidth + 6;
  283.                         Node->Height    = 2 + (2 * Height + Handle->GlyphHeight) / 2 + 2;
  284.                     }
  285.                     else
  286.                     {
  287.                         if(Node->Special.Button.Smaller)
  288.                         {
  289.                             Node->Width        = 4 + MaxWidth + 4;
  290.                             Node->Height    = 2 + Height + 2;
  291.                         }
  292.                         else
  293.                         {
  294.                             Node->Width        = 6 + MaxWidth + 6;
  295.                             Node->Height    = 3 + Height + 3;
  296.                         }
  297.                     }
  298.  
  299.                     Node->Label = "";
  300.                 }
  301.                 else
  302.                 {
  303.                     if(Node->Chars * Handle->GlyphWidth > Node->LabelWidth)
  304.                         Node->Width = Node->Chars * Handle->GlyphWidth;
  305.                     else
  306.                         Node->Width = Node->LabelWidth;
  307.  
  308.                     if(Node->Lines)
  309.                     {
  310.                         if(Node->Special.Button.ExtraFat)
  311.                         {
  312.                             Node->Width        = 6 + Handle->GlyphWidth + Node->Width + Handle->GlyphWidth + 6;
  313.                             Node->Height    = 2 + ((Node->Lines + 1) * Handle->GlyphHeight) / 2 + 2;
  314.                         }
  315.                         else
  316.                         {
  317.                             if(Node->Special.Button.Smaller)
  318.                             {
  319.                                 Node->Width        = 4 + Node->Width + 4;
  320.                                 Node->Height    = 2 + (Node->Lines * Handle->GlyphHeight) + 2;
  321.                             }
  322.                             else
  323.                             {
  324.                                 Node->Width        = 6 + Node->Width + 6;
  325.                                 Node->Height    = 3 + (Node->Lines * Handle->GlyphHeight) + 3;
  326.                             }
  327.                         }
  328.                     }
  329.                     else
  330.                     {
  331.                         if(Node->Special.Button.ExtraFat)
  332.                         {
  333.                             Node->Width        = 6 + Handle->GlyphWidth + Node->Width + Handle->GlyphWidth + 6;
  334.                             Node->Height    = 2 + (3 * Handle->GlyphHeight) / 2 + 2;
  335.                         }
  336.                         else
  337.                         {
  338.                             if(Node->Special.Button.Smaller)
  339.                             {
  340.                                 Node->Width        = 4 + Node->Width + 4;
  341.                                 Node->Height    = 2 + Handle->GlyphHeight + 2;
  342.                             }
  343.                             else
  344.                             {
  345.                                 Node->Width        = 6 + Node->Width + 6;
  346.                                 Node->Height    = 3 + Handle->GlyphHeight + 3;
  347.                             }
  348.                         }
  349.                     }
  350.                 }
  351.  
  352.                 Node->LabelWidth = 0;
  353.                 Node->LabelPlace = PLACE_IN;
  354.  
  355.                 break;
  356.  
  357.             case CHECKBOX_KIND:
  358.  
  359.                 Node->Width = Node->Height = (4 * Handle->GlyphHeight) / 3;
  360.  
  361.                 if(Node->Height < CHECKBOX_HEIGHT)
  362.                     Node->Height = CHECKBOX_HEIGHT;
  363.  
  364.                 if(!V39)
  365.                 {
  366.                     if(Node->Width < CHECKBOX_WIDTH)
  367.                         Node->Width = CHECKBOX_WIDTH;
  368.                 }
  369.                 else
  370.                     Node->Width = (Node->Height * Handle->AspectY) / Handle->AspectX;
  371.  
  372.                 break;
  373.  
  374.             case LISTVIEW_KIND:
  375.             {
  376.                 struct TextFont    *Font,*OldFont;
  377.                 LONG             GlyphWidth;
  378.  
  379.                 if(Node->Special.List.TextAttr)
  380.                 {
  381.                     if(!(Font = LTP_OpenFont(Node->Special.List.TextAttr)))
  382.                     {
  383.                         Handle->Failed = TRUE;
  384.  
  385.                         return;
  386.                     }
  387.  
  388.                         // Is this a fixed-width font?
  389.  
  390.                     if(Font->tf_Flags & FPF_PROPORTIONAL)
  391.                     {
  392.                             // We don't want it
  393.  
  394.                         CloseFont(Font);
  395.  
  396.                         Handle->Failed = TRUE;
  397.  
  398.                         return;
  399.                     }
  400.  
  401.                     OldFont = Handle->RPort.Font;
  402.  
  403.                     SetFont(&Handle->RPort,Font);
  404.  
  405.                     GlyphWidth = Handle->RPort.TxWidth;
  406.  
  407.                     Node->Special.List.FixedGlyphWidth    = Handle->RPort.TxWidth;
  408.                     Node->Special.List.FixedGlyphHeight    = Handle->GlyphHeight;
  409.                 }
  410.                 else
  411.                 {
  412.                     Font        = NULL;
  413.                     GlyphWidth    = Handle->GlyphWidth;
  414.                 }
  415.  
  416.                 i        = 0;
  417.                 Max        = 0;
  418.                 Width    = Node->Chars * GlyphWidth;
  419.  
  420.                 if((ULONG)Node->Special.List.Labels == 0xFFFFFFFF)
  421.                     Node->Min = Node->Max = -1;
  422.                 else
  423.                 {
  424.                     if(Node->Special.List.Labels)
  425.                     {
  426.                         struct Node *Item;
  427.  
  428.                         SCANLIST(Node->Special.List.Labels,Item)
  429.                         {
  430.                             i++;
  431.  
  432.                             if((Len = TextLength(&Handle->RPort,Item->ln_Name,strlen(Item->ln_Name))) > Max)
  433.                                 Max = Len;
  434.                         }
  435.                     }
  436.  
  437.                     if(Node->Special.List.IgnoreListContents)
  438.                         Max = 0;
  439.  
  440.                     Node->Max = i - 1;
  441.                 }
  442.  
  443.                 if(Max > Width && !Node->Special.List.SizeLocked)
  444.                 {
  445.                     Width = Max;
  446.  
  447.                     Node->Chars = (Width + GlyphWidth - 1) / GlyphWidth;
  448.  
  449.                     Width = Node->Chars * GlyphWidth;
  450.                 }
  451.  
  452.                 if(Node->Special.List.LockSize)
  453.                     Node->Special.List.SizeLocked = TRUE;
  454.  
  455.                 if(!V39)
  456.                     Node->Width = (4 + Width + 4) + (2 + 2 * Handle->GlyphWidth + 2) + 8;
  457.                 else
  458.                     Node->Width = (4 + Width + 4) + (2 + 2 * Handle->GlyphWidth + 2);
  459.  
  460.                 Node->Height = 2 + Node->Lines * Handle->GlyphHeight + 2;
  461.  
  462.                 if(Node->Special.List.ReadOnly)
  463.                 {
  464.                     if(Node->Special.List.LinkID != -1)
  465.                     {
  466.                         if(!V39)
  467.                             Node->Height += 2 + Handle->GlyphHeight + 2;
  468.                     }
  469.                 }
  470.                 else
  471.                 {
  472.                     if(Node->Special.List.LinkID == NIL_LINK)
  473.                     {
  474.                         if(!V39)
  475.                             Node->Height += 2 + Handle->GlyphHeight + 2;
  476.                     }
  477.                     else
  478.                     {
  479.                         if(Node->Special.List.LinkID != -1 && Node->Special.List.LinkID != NIL_LINK)
  480.                             Node->Height += 3 + Handle->GlyphHeight + 3;
  481.                     }
  482.                 }
  483.  
  484.                     // Switch back to the window font
  485.  
  486.                 if(Font)
  487.                 {
  488.                     SetFont(&Handle->RPort,OldFont);
  489.  
  490.                     CloseFont(Font);
  491.                 }
  492.  
  493.                 if(Node->Special.List.ExtraLabels)
  494.                 {
  495.                     for(i = Max = 0 ; Node->Special.List.ExtraLabels[i] ; i++)
  496.                     {
  497.                         if((Len = TextLength(&Handle->RPort,Node->Special.List.ExtraLabels[i],strlen(Node->Special.List.ExtraLabels[i]))) > Max)
  498.                             Max = Len;
  499.                     }
  500.  
  501.                     Node->Special.List.ExtraLabelWidth = Max;
  502.                 }
  503.  
  504.                 break;
  505.             }
  506.  
  507.             case MX_KIND:
  508.  
  509.                 i    = 0;
  510.                 Max    = 0;
  511.  
  512.                 while(Node->Special.Radio.Choices[i])
  513.                 {
  514.                     if((Width = TextLength(&Handle->RPort,Node->Special.Radio.Choices[i],strlen(Node->Special.Radio.Choices[i]))) > Max)
  515.                         Max = Width;
  516.  
  517.                     i++;
  518.                 }
  519.  
  520.                 Node->Max = i - 1;
  521.  
  522.                 Node->Special.Radio.LabelWidth = Max;
  523.  
  524.                 if(Node->LabelChars * Handle->GlyphWidth > Node->LabelWidth)
  525.                     Node->LabelWidth = Node->LabelChars * Handle->GlyphWidth;
  526.  
  527.                 Node->Height = MAX(MX_HEIGHT,Handle->GlyphHeight);
  528.  
  529.                 if(!V39)
  530.                     Node->Width = MX_WIDTH;
  531.                 else
  532.                 {
  533.                     Node->Width = (Node->Height * Handle->AspectY) / Handle->AspectX;
  534.  
  535.                     if(Node->Height < MX_HEIGHT)
  536.                     {
  537.                         Node->Height = MX_HEIGHT;
  538.                         Node->Width  = (Node->Height * Handle->AspectX) / Handle->AspectY;
  539.                     }
  540.                 }
  541.  
  542.                 Node->Lines  = i;
  543.                 Node->Height = Node->Lines * (Node->Height + Handle->InterHeight) - Handle->InterHeight;
  544.  
  545.                 break;
  546.  
  547. #ifdef DO_GAUGE_KIND
  548.             case GAUGE_KIND:
  549.  
  550.                 Width = TextLength(&Handle->RPort,"0%100%",6) + 2 * Handle->GlyphWidth;
  551.  
  552.                 if(Handle->GlyphWidth * Node->Chars > Width)
  553.                     Width = Handle->GlyphWidth * Node->Chars;
  554.  
  555.                 Node->Width = 6 + Width + 6;
  556.  
  557.                 if(Node->Special.Gauge.NoTicks)
  558.                     Node->Height = 3 + Handle->GlyphHeight + 3;
  559.                 else
  560.                     Node->Height = 3 + Handle->GlyphHeight + 2 + Handle->InterHeight + Handle->GlyphHeight + 3;
  561.  
  562.                 if(Node->Special.Gauge.Discrete)
  563.                 {
  564.                     Width = ((Node->Width - 6 - 6) + 9) / 10;
  565.  
  566.                     Node->Width = 2 + Width * 10 + 2;
  567.                 }
  568.  
  569.                 break;
  570. #endif
  571.  
  572. #ifdef DO_TAPEDECK_KIND
  573.             case TAPEDECK_KIND:
  574.             {
  575.                 LONG Width,Height,OrigWidth,Attempt = 4;
  576.  
  577.                 Width = TextLength(&Handle->RPort,"AA",2);
  578.  
  579.                 if(Width < 2 * Handle->GlyphWidth);
  580.                     Width = 2 * Handle->GlyphWidth;
  581.  
  582.                 if(Width < 2 * Handle->GlyphHeight)
  583.                     Width = 2 * Handle->GlyphHeight;
  584.  
  585.                 if(Node->Special.TapeDeck.Smaller)
  586.                     Width = (3 * Width) / 4;
  587.  
  588.                 if(Width & 1)
  589.                     Width++;
  590.  
  591.                 OrigWidth = Width;
  592.  
  593.                 do
  594.                 {
  595.                     Width    = 1 + ((((OrigWidth + 5) / 6) * 6) & ~1);
  596.                     Height    = (Handle->AspectX * Width) / (Handle->AspectY * 2);
  597.  
  598.                     OrigWidth += 2;
  599.                     Attempt--;
  600.                 }
  601.                 while(Height < 6 && Attempt > 0);
  602.  
  603.                 if(!(Height & 1))
  604.                     Height++;
  605.  
  606.                 if(Node->Special.TapeDeck.ButtonType == TDBT_BACKWARD || Node->Special.TapeDeck.ButtonType == TDBT_FORWARD)
  607.                     Node->Special.TapeDeck.ButtonWidth = Width;
  608.                 else
  609.                     Node->Special.TapeDeck.ButtonWidth = Width / 2;
  610.  
  611.                 Node->Special.TapeDeck.ButtonHeight = Height;
  612.  
  613.                 if(Handle->GlyphWidth * Node->Chars > Width)
  614.                     Width = Handle->GlyphWidth * Node->Chars;
  615.  
  616.                 Node->Width        = 6 + Width + 6;
  617.                 Node->Height    = 3 + Height + 3;
  618.  
  619.                 break;
  620.             }
  621. #endif    /* DO_TAPEDECK_KIND */
  622.  
  623.             case CYCLE_KIND:
  624.  
  625.                     // NOTE: This does not include the width of the
  626.                     //       cycle glyph which is by default 26 pixels
  627.                     //       wide.
  628.  
  629.                 Node->Width = 6 + Node->Chars * Handle->GlyphWidth + 6;
  630.  
  631.                 Width = 0;
  632.  
  633.                 if(Node->Special.Cycle.Choices)
  634.                 {
  635.                     for(i = 0 ; Node->Special.Cycle.Choices[i] ; i++)
  636.                     {
  637.                         if((Len = TextLength(&Handle->RPort,Node->Special.Cycle.Choices[i],strlen(Node->Special.Cycle.Choices[i]))) > Width)
  638.                             Width = Len;
  639.                     }
  640.  
  641.                     Node->Max = i - 1;
  642.                 }
  643.  
  644.                 Max = 6 + Width + 6;
  645.  
  646.                 if(Node->Width < Max)
  647.                     Node->Width = Max;
  648.  
  649.                     // Add the remainder of the cycle glyph
  650.  
  651.                 Node->Width += 20;
  652.  
  653.                 Node->Height = 3 + Handle->GlyphHeight + 3;
  654.  
  655.                 break;
  656.  
  657. #if defined(DO_POPUP_KIND) && defined(DO_BOOPSI_KIND)
  658.             case POPUP_KIND:
  659.  
  660.                     // NOTE: This is the number of pixels the popup glyph
  661.                     //       will need. It will not enter the calculation
  662.                     //       until the maximum size of the hit box is
  663.                     //       calculated.
  664.  
  665.                 Plus = (4 + ((TextLength(&Handle->RPort,"M",1) & ~1) + 1) + 2 + 4) + (Handle->GlyphHeight * Handle->DrawInfo->dri_Resolution.Y) / Handle->DrawInfo->dri_Resolution.X + 2;
  666.  
  667.                 Node->Width = 6 + Node->Chars * Handle->GlyphWidth + 6;
  668.  
  669.                 Width = 0;
  670.  
  671.                 if(Node->Special.Popup.Choices)
  672.                 {
  673.                     for(i = 0 ; Node->Special.Popup.Choices[i] ; i++)
  674.                     {
  675.                         if((Len = TextLength(&Handle->RPort,Node->Special.Popup.Choices[i],strlen(Node->Special.Popup.Choices[i]))) > Width)
  676.                             Width = Len;
  677.                     }
  678.  
  679.                     Node->Max = i - 1;
  680.                 }
  681.  
  682.                 Max = 6 + Width + 6;
  683.  
  684.                 if(Node->Width < Max)
  685.                     Node->Width = Max;
  686.  
  687.                     // Add the glyph width
  688.  
  689.                 Node->Width += Plus;
  690.  
  691.                 Node->Height = 3 + Handle->GlyphHeight + 3;
  692.  
  693.                 break;
  694. #endif
  695.  
  696. #if defined(DO_TAB_KIND) && defined(DO_BOOPSI_KIND)
  697.             case TAB_KIND:
  698.  
  699.                 if(!Node->Special.Tab.Choices)
  700.                     Handle->Failed = TRUE;
  701.                 else
  702.                 {
  703.                     struct IBox Box;
  704.  
  705.                     Width = Node->Chars * Handle->GlyphWidth;
  706.  
  707.                     for(i = 0 ; Node->Special.Tab.Choices[i] ; i++);
  708.  
  709.                     Node->Max = i - 1;
  710.  
  711.                     Node->Label = NULL;
  712.  
  713.                     if(!LTP_ObtainTabSize(&Box,
  714.                         TIA_Labels,        Node->Special.Tab.Choices,
  715.                         TIA_DrawInfo,    Handle->DrawInfo,
  716.                         TIA_Font,        Handle->TextAttr,
  717.                         TIA_SizeType,    GDOMAIN_MINIMUM,
  718.                     TAG_DONE))
  719.                         Handle->Failed = TRUE;
  720.                     else
  721.                     {
  722.                         if(Width < Box.Width)
  723.                             Width = Box.Width;
  724.  
  725.                         Node->Width        = Width;
  726.                         Node->Height    = Box.Height;
  727.                     }
  728.                 }
  729.  
  730.                 break;
  731. #endif
  732.             case PALETTE_KIND:
  733.  
  734.                 if(Node->Special.Palette.UsePicker)
  735.                 {
  736.                     Node->Height = 3 + Handle->GlyphHeight + 3;
  737.                     Node->Width = (Node->Height * Handle->AspectY) / Handle->AspectX;
  738.  
  739.                     Node->Special.Palette.IndicatorWidth = Node->Width;
  740.  
  741.                     Node->Width += LTP_GetPickerSize(Handle);
  742.                 }
  743.                 else
  744.                 {
  745.                     if(Node->Special.Palette.NumColours)
  746.                         Node->Max = Node->Min + Node->Special.Palette.NumColours - 1;
  747.                     else
  748.                     {
  749.                         if(!Node->Special.Palette.Depth)
  750.                             Node->Special.Palette.Depth = 1;
  751.  
  752.                         Node->Special.Palette.NumColours = 1L << Node->Special.Palette.Depth;
  753.  
  754.                         Node->Max = Node->Min + Node->Special.Palette.NumColours - 1;
  755.                     }
  756.  
  757.                     if(Node->Special.Palette.SmallPalette)
  758.                     {
  759.                         Node->Width        = Handle->GlyphWidth * (Node->Max - Node->Min + 1) + 4;
  760.                         Node->Height    = 1 + Handle->GlyphHeight + 1;
  761.  
  762.                         if((Node->Width - 4) / (Node->Max - Node->Min + 1) < 8 && Node->Height < 2 * 8)
  763.                             Node->Width = 8 * (Node->Max - Node->Min + 1) + 4;
  764.  
  765.                         Node->Width += 2 * Handle->GlyphWidth;
  766.                     }
  767.                     else
  768.                     {
  769.                         Node->Width        = 2 * Handle->GlyphWidth * (Node->Max - Node->Min + 1);
  770.                         Node->Height    = 2 * Handle->GlyphHeight;
  771.                     }
  772.  
  773.                     if(Node->Width < 20)
  774.                         Node->Width = 20;
  775.  
  776.                     if(Node->Chars * Handle->GlyphWidth > Node->Width)
  777.                         Node->Width = Node->Chars * Handle->GlyphWidth;
  778.  
  779.                     if(Node->Special.Palette.NumColours > 16)
  780.                     {
  781.                         Node->Height    *= 2;
  782.                         Node->Width        /= 2;
  783.                     }
  784.  
  785.                     if(Node->Lines)
  786.                     {
  787.                         if(!Node->Chars)
  788.                             Node->Width = Handle->GlyphWidth;
  789.                         else
  790.                             Node->Width = Node->Chars * Handle->GlyphWidth;
  791.  
  792.                         Node->Height = Node->Lines * Handle->GlyphHeight;
  793.                     }
  794.  
  795.                     if(Node->Special.Palette.ColourTable && !Node->Special.Palette.TranslateBack)
  796.                     {
  797.                         if(Node->Special.Palette.TranslateBack = LTP_Alloc(Handle,256))
  798.                         {
  799.                             LONG i;
  800.  
  801.                             for(i = Node->Min ; i <= Node->Max ; i++)
  802.                                 Node->Special.Palette.TranslateBack[Node->Special.Palette.ColourTable[i]] = i;
  803.                         }
  804.                     }
  805.                 }
  806.  
  807.                 break;
  808.  
  809.             case SCROLLER_KIND:
  810.  
  811.                 if(Node->Special.Scroller.Vertical)
  812.                 {
  813.                     if(Node->Special.Scroller.Thin)
  814.                         Node->Width = 6 + Handle->GlyphWidth + 6;
  815.                     else
  816.                         Node->Width = 6 + (3 * Handle->GlyphWidth) / 2 + 6;
  817.  
  818.                     Node->Height = 2 + Node->Lines * Handle->GlyphHeight;
  819.  
  820.                     if(Node->Special.Scroller.Arrows)
  821.                     {
  822.                         LONG ScrollerHeight = (Handle->AspectX * Node->Width) / Handle->AspectY;
  823.  
  824.                         if(Node->Height < 2 + Node->Lines * Handle->GlyphHeight + 2 * ScrollerHeight)
  825.                             Node->Height = 2 + Node->Lines * Handle->GlyphHeight + 2 * ScrollerHeight;
  826.  
  827.                         Node->Special.Scroller.ArrowSize = ScrollerHeight;
  828.                     }
  829.                 }
  830.                 else
  831.                 {
  832.                     Node->Width  = 6 + Node->Chars * Handle->GlyphWidth + 6;
  833.                     Node->Height = 2 + Handle->GlyphHeight;
  834.  
  835.                     if(Node->Special.Scroller.Arrows)
  836.                     {
  837.                         LONG ScrollerWidth = (Handle->AspectY * Node->Height) / Handle->AspectX;
  838.  
  839.                         if(Node->Width < 6 + Handle->GlyphWidth + 2 * ScrollerWidth + 6)
  840.                             Node->Width = 6 + Handle->GlyphWidth + 2 * ScrollerWidth + 6;
  841.  
  842.                         Node->Special.Scroller.ArrowSize = ScrollerWidth;
  843.                     }
  844.                 }
  845.  
  846.                 break;
  847.  
  848.             case SLIDER_KIND:
  849.             {
  850.                 BOOL CheckIt;
  851.  
  852.                 Node->Width        = 6 + Node->Chars * Handle->GlyphWidth + 6;
  853.                 Node->Height    = 2 + Handle->GlyphHeight + 2;
  854.  
  855.                 CheckIt = (!Node->Special.Slider.MaxLevelLen || !Node->Special.Slider.LevelWidth || Handle->Rescaled);
  856.  
  857.                 if(Node->Special.Slider.LevelFormat && CheckIt)
  858.                     LTP_LevelWidth(Handle,Node->Special.Slider.LevelFormat,Node->Special.Slider.DispFunc,Node->Min,Node->Max,&Node->Special.Slider.LevelWidth,&Node->Special.Slider.MaxLevelLen,Node->Special.Slider.FullLevelCheck);
  859.  
  860.                 if(Node->Special.Slider.LevelFormat && !V40)
  861.                 {
  862.                     if(Node->Special.Slider.MaxLevelLen * Handle->RPort.TxWidth < Node->Special.Slider.LevelWidth)
  863.                         Node->Special.Slider.MaxLevelLen = (Node->Special.Slider.LevelWidth + Handle->RPort.TxWidth - 1) / Handle->RPort.TxWidth;
  864.                 }
  865.  
  866.                 if(Node->Special.Slider.LevelFormat && Node->Special.Slider.LevelPlace == PLACETEXT_LEFT && Node->LabelPlace == PLACE_LEFT && Node->Label && CheckIt)
  867.                 {
  868.                     LONG    space,len;
  869.                     STRPTR    Buffer;
  870.  
  871.                     space = TextLength(&Handle->RPort," ",1);
  872.                     space = (Node->Special.Slider.LevelWidth + space - 1) / space;
  873.  
  874.                     if(!V40 && (Handle->RPort.TxFlags & FPF_PROPORTIONAL))
  875.                     {
  876.                         Node->Special.Slider.MaxLevelLen++;
  877.  
  878.                         space++;
  879.                     }
  880.  
  881.                     if(Node->Special.Slider.OriginalLabel)
  882.                         LTP_Free(Handle,Node->Label,strlen(Node->Label) + 1);
  883.                     else
  884.                         Node->Special.Slider.OriginalLabel = Node->Label;
  885.  
  886.                     len = strlen(Node->Special.Slider.OriginalLabel);
  887.  
  888.                     if(Buffer = LTP_Alloc(Handle,len + space + 1))
  889.                     {
  890.                         strcpy(Buffer,Node->Special.Slider.OriginalLabel);
  891.  
  892.                         while(space > 0)
  893.                         {
  894.                             Buffer[len] = ' ';
  895.                             len++;
  896.                             space--;
  897.                         }
  898.  
  899.                         Buffer[len] = 0;
  900.  
  901.                         Node->Label            = Buffer;
  902.                         Node->LabelWidth    = LT_LabelWidth(Handle,Node->Label);
  903.                     }
  904.                     else
  905.                         break;
  906.                 }
  907.  
  908.                 if(Node->LabelChars * Handle->GlyphWidth > Node->LabelWidth)
  909.                     Node->LabelWidth = Node->LabelChars * Handle->GlyphWidth;
  910.  
  911.                 break;
  912.             }
  913.  
  914.             case TEXT_KIND:
  915.  
  916.                 if(Node->Special.Text.Text && !Node->Special.Text.SizeLocked)
  917.                     Max = TextLength(&Handle->RPort,Node->Special.Text.Text,strlen(Node->Special.Text.Text));
  918.                 else
  919.                     Max = 0;
  920.  
  921.                 Width = Node->Chars * Handle->GlyphWidth;
  922.  
  923.                 if(!Node->Special.Text.SizeLocked && Node->Special.Text.LockSize)
  924.                 {
  925.                     LONG Chars = (Width + Handle->GlyphWidth - 1) / Handle->GlyphWidth;
  926.  
  927.                     if(Chars > Node->Chars)
  928.                         Node->Chars = Chars;
  929.  
  930.                     Max = Width = Node->Chars * Handle->GlyphWidth;
  931.                 }
  932.  
  933.                 if(Max > Width)
  934.                     Width = Max;
  935.  
  936.                 Node->Width        = 6 + Width + 6;
  937.                 Node->Height    = 3 + Handle->GlyphHeight + 3;
  938.  
  939.                 if(Node->Special.Text.UsePicker)
  940.                     Node->Width += LTP_GetPickerSize(Handle);
  941.  
  942.                 if(Node->Special.Text.LockSize)
  943.                     Node->Special.Text.SizeLocked = TRUE;
  944.  
  945.                 break;
  946.  
  947.             case NUMBER_KIND:
  948.             case INTEGER_KIND:
  949.             case STRING_KIND:
  950.             case PASSWORD_KIND:
  951.  
  952.                 Node->Width        = 6 + Node->Chars * Handle->GlyphWidth + 6;
  953.                 Node->Height    = 3 + Handle->GlyphHeight + 3;
  954.  
  955.                 if(Node->Type == STRING_KIND && Node->Special.String.UsePicker)
  956.                     Node->Width += LTP_GetPickerSize(Handle);
  957.  
  958.                 if(Node->Type == INTEGER_KIND && Node->Special.Integer.UseIncrementers)
  959.                     Node->Width += 2 * (4 + Handle->GlyphWidth + 4);
  960.  
  961.                 break;
  962.         }
  963.  
  964.         if(Node->LabelWidth > Node->Width && (Node->LabelPlace == PLACE_ABOVE || Node->LabelPlace == PLACE_BELOW))
  965.             Node->Width = Node->LabelWidth;
  966.     }
  967. }
  968.